from pydantic import BaseModel, EmailStr, field_validator
from typing import Optional
from datetime import datetime

# 基础用户模型
class UserBase(BaseModel):
    email: Optional[EmailStr] = None
    nickname: Optional[str] = None
    avatar: Optional[str] = None
    gender: Optional[int] = 0
    status: Optional[int] = 1

# 创建用户请求模型
class UserCreate(UserBase):
    email: EmailStr
    password: str
    
    @field_validator('password')
    @classmethod
    def password_min_length(cls, v):
        if len(v) < 6:
            raise ValueError('密码长度至少为6位')
        return v

# 用户登录请求模型
class UserLogin(BaseModel):
    email: EmailStr
    password: str

# 微信登录请求模型
class WechatLogin(BaseModel):
    code: str

# 用户信息响应模型
class UserResponse(UserBase):
    id: int
    login_type: str
    last_login_at: Optional[datetime] = None
    created_at: datetime
    updated_at: datetime

    class Config:
        from_attributes = True

# Token响应模型
class Token(BaseModel):
    access_token: str
    token_type: str
    user: UserResponse 